﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SuDaExpress
{
    public partial class ShanChuBaoShi : Form
    {
        public ShanChuBaoShi()
        {
            InitializeComponent();
        }
        DBHelper db = new DBHelper();
        private void button1_Click(object sender, EventArgs e)
        {
            if(tex_kuaididanhao.Text == "")
            {
                MessageBox.Show("单号不能为空", "提示");
                this.tex_kuaididanhao.Focus();
            }
            else
            {
                if (!PanDuanChaXun())
                {
                    ShanChu();
                }
            }
        }
        public bool PanDuanChaXun()
        {
            string sql = string.Format("select count(*) from UserExpressXinXI where Odd = {0}", Convert.ToInt32(tex_kuaididanhao.Text));
            if (tex_kuaididanhao.Text == "")
            {
                MessageBox.Show("请输入单号", "提示");
                this.tex_kuaididanhao.Focus();
            }
            else if (tex_kuaididanhao.Text != "")
            {
                int lingshi = Convert.ToInt32(db.GetOne(sql));
                if (lingshi > 0)
                {
                    return false;
                }
                else
                {
                    MessageBox.Show("单号输入错误或无此快递", "提示");
                }
            }
            return true;
        }
        public void ShanChu()
        {
            string sql = string.Format("delete from KuaiDiBaoShi where Odd = {0}", Convert.ToInt32(tex_kuaididanhao.Text));
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(sql, db.Conn);
            //sda.Fill(ds.Tables["KuaiDiBaoShi"]);
            SqlCommandBuilder builder = new SqlCommandBuilder(sda);
            sda.Update(ds, "KuaiDiBaoShi");
        }
    }
}
